<template>
    <div class="">
        <!-- 表格 -->
        <el-table border :data="catelist" style="width: 100%" row-key="id" default-expand-all
            :tree-props="{ children: 'children'}">
            <el-table-column label="分类编号" width="80" prop="id">
            </el-table-column>
            <el-table-column label="分类名称" width="200" prop="catename">
            </el-table-column>
            <el-table-column label="图片" width="200">
                <template slot-scope="item">
                    <img v-if="item.row.img" class="imgUrl" :src="item.row.img" alt="">
                </template>
            </el-table-column>
            <el-table-column label="状态">
                <template slot-scope="item">
                    <div v-if="item.row.status == 1">
                        <el-button type="success" plain disabled>启用</el-button>
                    </div>
                    <div v-else>
                        <el-button type="danger" plain disabled>禁用</el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="item">
                    <div>
                        <el-button size="mini" type="primary" icon="el-icon-edit"
                            @click="edit(item.row.id)">编辑</el-button>
                        <el-button size="mini" type="danger" icon="el-icon-delete"
                            @click="del(item.row.id)">删除</el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import { cateDel } from '../../request/api'
import { mapGetters, mapActions } from 'vuex'
export default {
    data() {
        return {

        }
    },
    computed: {
        ...mapGetters({
            catelist: 'classify/getCate'
        })
    },
    mounted() {
        // catelist().then(res=>{
        //     console.log(res,'/////');
        // })
        this.getCateAction()
    },
    methods: {
        edit(id) {
            this.$emit('edit', id)
        },
        ...mapActions({
            getCateAction: 'classify/changeCateAction'
        }),
        del(id) {
            this.$confirm('你确定要删除这条数据吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                // 调用删除接口
                cateDel({ id }).then(res => {
                    console.log(res, '删除');
                    if (res.code == 200) {
                        this.$message.success(res.msg)
                        // 重新触发
                        this.getCateAction()
                    } else {
                        this.$message.error(res.msg)
                    }
                })
                //   this.$message({
                //     type: 'success',
                //     message: '删除成功!'
                //   });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        }
    }
}
</script>
<style scoped >
.imgUrl {
    width: 60px;
    height: 60px;
}
</style>